package gui.view;

import gui.controller.MaxThreadsChoiceListener;

import java.beans.PropertyChangeListener;

import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

/**
 * 
 * @author Felix Schliephacke
 * 
 */
public class MaxThreadsChoiceBox extends JSpinner {

	private static final long serialVersionUID = -2640065398224787141L;
	private MaxThreadsChoiceListener listener;

	public MaxThreadsChoiceBox() {
		super(new SpinnerNumberModel(
				Runtime.getRuntime().availableProcessors(), 1,
				Integer.MAX_VALUE, 1));
	}

	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		super.addPropertyChangeListener(listener);
		this.getListener().addPropertyChangeListener(listener);
	}

	@Override
	public void removePropertyChangeListener(PropertyChangeListener listener) {
		super.removePropertyChangeListener(listener);
		this.getListener().removePropertyChangeListener(listener);
	}

	private MaxThreadsChoiceListener getListener() {
		if (this.listener == null) {
			this.listener = new MaxThreadsChoiceListener(this);
			this.addChangeListener(this.listener);
		}
		return this.listener;
	}

}
